package com.yyx.demo.config;

import com.yyx.demo.config.statement.StatementHandler;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;

public class MyExcutor implements Excutor {
    private MyConfiguration xmlConfiguration = new MyConfiguration();

    public <T> T query(Function function, Object parameter) throws SQLException, IllegalAccessException, InstantiationException, InvocationTargetException {

        StatementHandler handler = MyConfiguration.newStatementHandler();
        return (T) handler.query(handler.instantiateStatement(getConnection(),function.getSql()),parameter.toString(),function);
    }

    private Connection getConnection() {
        try {
            Connection connection=xmlConfiguration.build("mybatis-config.xml");
            return connection;
        }catch (Exception e){

        }
        return null;
    }
}
